set more off
set matsize 1100

* set your directory here
global dir ""
use "$dir/Data/did_gender.dta", replace

*estpost summarize general_total_A_0_d general_total_B_0_d general_total_H_0_d general_total_W_0_d general_total_A_1_d general_total_B_1_d general_total_H_1_d general_total_W_1_d, listwise

mean general_total_A_0_d 
mean general_total_B_0_d 
mean general_total_H_0_d 
mean general_total_W_0_d 
mean general_total_A_1_d 
mean general_total_B_1_d 
mean general_total_H_1_d 
mean general_total_W_1_d


foreach j in A B H W 0 1 {
	gen cand_`j'_all = (cand_`j'_d==1 | cand_`j'_r==1)
}
foreach i in A B H W {
	foreach j in 0 1 {
		foreach k in d r all {
			gen cand_int_`i'_`j'_`k' = cand_`i'_`k'*cand_`j'_`k'
		}
		foreach k in d r {
			gen lead1_cand_int_`i'_`j'_`k' = lead1_cand_`i'_`k'*lead1_cand_`j'_`k'
			gen lead2_cand_int_`i'_`j'_`k' = lead2_cand_`i'_`k'*lead2_cand_`j'_`k'
			gen lead3_cand_int_`i'_`j'_`k' = lead3_cand_`i'_`k'*lead3_cand_`j'_`k'
		}
	}
}
drop cand_*W_0*

foreach k in d r all {
	*gen cand_NW_`k' = 1 - cand_W_`k'
	foreach j in 0 1 {
		gen cand_int_NW_`j'_`k' = cand_NW_`k'*cand_`j'_`k'

	}
}



global cand_covars_d inc_d Open_Seat_d held_office_d religion_d race_d profession_d milService_d ps_dw1_d ps_dw2_d quality_chall_d cq_forecast_d relig_rc_d relig_md_d relig_bp_d relig_pr_d relig_ep_d relig_jw_d career_law_d career_bus_d career_edu_d career_pol_d career_agr_d military_d
global cand_covars_r inc_r Open_Seat_r held_office_r religion_r race_r profession_r milService_r ps_dw1_r ps_dw2_r quality_chall_r cq_forecast_r relig_rc_r relig_md_r relig_bp_r relig_pr_r relig_ep_r relig_jw_r career_law_r career_bus_r career_edu_r career_pol_r career_agr_r military_r

foreach i in total {
	foreach j in 0 1 {
		foreach k in d r all {
			foreach l in d r all {		
				foreach m in share log {
		
					
					* just gender
					qui eststo: xi: areg general_`m'`i'_`j'_`l' cand_1_`k' i.cycle i.district_final, a(district_final) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_`j'_contrib`l'_cand`k'_general.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_`j'_`l' cand_1_`k' $cand_covar_`k' d_* i.cycle i.district_final, a(district_final) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_`j'_contrib`l'_cand`k'_general_allcovar.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_`j'_`l' cand_1_`k' d_* i.cycle i.district_final, a(district_final) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_`j'_contrib`l'_cand`k'_general_candcovar.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_`j'_`l' cand_1_`k' d_* i.cycle, a(cycle) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_`j'_contrib`l'_cand`k'_general_nofe.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_`j'_`l' cand_1_`k' cand_covar_`k' d_* i.cycle, a(cycle) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_`j'_contrib`l'_cand`k'_general_candnofe.csv", b se plain wide replace 	
					eststo clear
					
					
					* white and non-white candidates x gender
					qui eststo: xi: areg general_`m'`i'_NW_`j'_`l' cand_int_NW_*_`k' cand_int_W_1_`k' i.cycle i.district_final, a(district_final) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_NW_`j'_contrib`l'_cand`k'_general.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_NW_`j'_`l' cand_int_NW_*_`k' cand_int_W_1_`k' pct_W i.cycle i.district_final, a(district_final) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_NW_`j'_contrib`l'_cand`k'_general_covar.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_NW_`j'_`l' cand_int_NW_*_`k' cand_int_W_1_`k' $cand_covar_`k' pct_W i.cycle i.district_final, a(district_final) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_NW_`j'_contrib`l'_cand`k'_general_candcovar.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_NW_`j'_`l' cand_int_NW_*_`k' cand_int_W_1_`k' pct_W d_* i.cycle i.district_final, a(district_final) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_NW_`j'_contrib`l'_cand`k'_general_allcovar.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_NW_`j'_`l' cand_int_NW_*_`k' cand_int_W_1_`k' pct_W d_* i.cycle, a(cycle) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_NW_`j'_contrib`l'_cand`k'_general_nofe.csv", b se plain wide replace 	
					eststo clear
					
					qui eststo: xi: areg general_`m'`i'_NW_`j'_`l' cand_int_NW_*_`k' cand_int_W_1_`k' $cand_covar_`k' pct_W d_* i.cycle, a(cycle) robust cluster(district_final)
					esttab using "$dir/Output/house_`m'`i'_NW_`j'_contrib`l'_cand`k'_general_candnofe.csv", b se plain wide replace 	
					eststo clear
					
					* broken out by ethnorace x gender
					foreach n in A B H W {
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l' cand_int_*_`k' i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l' cand_int_*_`k' pct_`n' i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_covar.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l' cand_int_*_`k' pct_`n' $cand_covar_`k' i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_candcovar.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l' cand_int_*_`k' pct_`n' d_* i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_allcovar.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l' cand_int_*_`k' pct_`n' d_* i.cycle, a(cycle) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_nofe.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l' cand_int_*_`k' pct_`n' $cand_covar_`k' d_* i.cycle, a(cycle) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_candnofe.csv", b se plain wide replace 	
						eststo clear
						
					}
					
				}
			}
		}
	}
}

* base and interactions
foreach i in total {
	foreach j in d r {
		foreach l in d r {		
			foreach m in share log {
				foreach n in A B H W {
					qui eststo: xi: areg general_`m'`i'_`n'_0_`l' cand_1_`j' cand_A_`j' cand_B_`j' cand_H_`j' cand_int_A_1_`j' cand_int_B_1_`j' cand_int_H_1_`j' pct_* d_* i.cycle, a(cycle) robust cluster(district_final)
					qui eststo: xi: areg general_`m'`i'_`n'_1_`l' cand_1_`j' cand_A_`j' cand_B_`j' cand_H_`j' cand_int_A_1_`j' cand_int_B_1_`j' cand_int_H_1_`j' pct_* d_* i.cycle, a(cycle) robust cluster(district_final)
				}
				esttab using "$dir/Output/reg_`m'`i'_contrib`l'_cand`j'.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) label mtitles("Asian Men" "Asian Women" "Black Men" "Black Women" "Latino Men" "Latino Women" "White Men" "White Women") 
				eststo clear
			}
		}
	}
}			


foreach i in total {
	foreach j in 0 1 {
		foreach k in d r all {
			foreach l in d r all {		
				foreach m in share log {
					foreach n in NW W {
		
						
						* white and non-white candidates x gender
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l'  cand_int_NW_*_`k' cand_int_W_1_`k' i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_2g_general.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l'  cand_int_NW_*_`k' cand_int_W_1_`k' pct_W i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_2g_covar.csv", b se plain wide replace 	
						eststo clear
	
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l'  cand_int_NW_*_`k' cand_int_W_1_`k' pct_W d_* i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_2g_allcovar.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l'  cand_int_NW_*_`k' cand_int_W_1_`k' $cand_covar_`k' pct_W d_* i.cycle i.district_final, a(district_final) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_2g_candcovar.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l'  cand_int_NW_*_`k' cand_int_W_1_`k' pct_W d_* i.cycle, a(cycle) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_2g_nofe.csv", b se plain wide replace 	
						eststo clear
						
						qui eststo: xi: areg general_`m'`i'_`n'_`j'_`l'  cand_int_NW_*_`k' cand_int_W_1_`k' $cand_covar_`k' pct_W d_* i.cycle, a(cycle) robust cluster(district_final)
						esttab using "$dir/Output/house_`m'`i'_`n'_`j'_contrib`l'_cand`k'_general_2g_candnofe.csv", b se plain wide replace 	
						eststo clear
						
					}
				}
			}
		}
	}
}


gen general_total_d = log(general_total_d)
gen general_total_r = log(general_total_r)
gen general_total_diff = general_total_d - general_total_r
* just gender
eststo: xi: areg general_total_diff cand_1_d i.cycle, a(district_final) robust cluster(district_final)
eststo: xi: areg general_total_diff cand_1_r i.cycle, a(district_final) robust cluster(district_final)
* fully saturated
eststo: xi: areg general_total_diff cand_int_A_0_d cand_int_A_1_d cand_int_B_0_d cand_int_B_1_d cand_int_H_0_d cand_int_H_1_d cand_int_W_1_d i.cycle, a(district_final) robust cluster(district_final)
eststo: xi: areg general_total_diff cand_int_A_0_r cand_int_A_1_r cand_int_B_0_r cand_int_B_1_r cand_int_H_0_r cand_int_H_1_r cand_int_W_1_r i.cycle, a(district_final) robust cluster(district_final)
* subset by race
foreach i in A B H W NW {
	eststo: xi: areg general_logtotal_diff cand_1_d i.cycle if cand_`i'_d==1, a(district_final) robust cluster(district_final)
	eststo: xi: areg general_logtotal_diff cand_1_r i.cycle if cand_`i'_r==1, a(district_final) robust cluster(district_final)
}
esttab using "$dir/Output/fundraising_parity.csv", b se plain wide replace 	
esttab using "$dir/Output/fundraising_parity.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001)


* long format
use "$dir/Data/did_gender.dta", replace

drop if cycle>2010

eststo clear

eststo: xi: areg race_gender_share same_race i.id d_* i.cycle, a(district_final) robust cluster(district_final)
eststo: xi: areg race_gender_share same_gender i.id d_* i.cycle, a(district_final) robust cluster(district_final)
eststo: xi: areg race_gender_share same_race##same_gender i.id d_* i.cycle, a(district_final) robust cluster(district_final)

eststo: xi: areg race_gender_logtotal same_race i.id d_* i.cycle, a(district_final) robust cluster(district_final)
eststo: xi: areg race_gender_logtotal same_gender i.id d_* i.cycle, a(district_final) robust cluster(district_final)
eststo: xi: areg race_gender_logtotal same_race##same_gender i.id d_* i.cycle, a(district_final) robust cluster(district_final)
esttab using "$dir/Output/ingroup_gender_race_did.csv", b se plain wide replace 	


****Regression table****
*Dem
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem.csv", b se plain wide replace 	

*Republican
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep.csv", b se plain wide replace 	


*Women only
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_women.csv", b se plain wide replace 

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_women.csv", b se plain wide replace 	



*Women of Color ONLY
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_woc.csv", b se plain wide replace 	

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_woc.csv", b se plain wide replace 	

** without FEs **
*Dem
eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race i.id pct_* d_* inc i.cycle if party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_gender i.id pct_* d_* inc i.cycle if party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender i.id pct_* d_* inc i.cycle if party=="d", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_nofe.csv", b se plain wide replace 	

*Republican
eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race i.id pct_* d_* inc i.cycle if party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_gender i.id pct_* d_* inc i.cycle if party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender i.id pct_* d_* inc i.cycle if party=="r", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_nofe.csv", b se plain wide replace 	


*Women only
eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_women_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_women_nofe.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_women_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_women_nofe.csv", b se plain wide replace 	

*Women of Color ONLY
eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d",robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_woc_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_dem_woc_nofe.csv", b se plain wide replace 	

eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_woc_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_rep_woc_nofe.csv", b se plain wide replace 


* GRANGER CAUSALITY TEST
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_gender lead1_same_gender lead2_same_gender lead3_same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
margins lead1_same_gender 
margins, dydx(lead1_same_gender lead2_same_gender lead3_same_gender)
eststo: quietly: xi: areg race_gender_logtotal same_race lead1_same_race lead2_same_race lead3_same_race i.id d_* inc i.cycle if (id!="W1"&id!="W0") & party=="d", a(district_final) robust cluster(district_final)
estat ic	
esttab using "$dir/Output/granger_ingroup_gender_race_logtotal_dem_women.csv", b se plain wide replace 


*** totals instead of logtotals ***
****Regression table****
*Dem
eststo clear
eststo: quietly: xi: areg race_gender_total same_race i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_gender i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_race##same_gender i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_dem.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_dem.csv", b se plain wide replace 	

*Republican
eststo clear
eststo: quietly: xi: areg race_gender_total same_race i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_gender i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_race##same_gender i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_rep.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_rep.csv", b se plain wide replace 	


*Women only
eststo clear
eststo: quietly: xi: areg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_dem_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_dem_women.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: areg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_rep_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_rep_women.csv", b se plain wide replace 	



*Women of Color ONLY
eststo clear
eststo: quietly: xi: areg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_dem_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_dem_woc.csv", b se plain wide replace 	

eststo clear
eststo: quietly: xi: areg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_rep_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_rep_woc.csv", b se plain wide replace 	

** without FEs **
*Dem
eststo clear
eststo: quietly: xi: reg race_gender_total same_race i.id pct_* d_* inc i.cycle if party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_gender i.id pct_* d_* inc i.cycle if party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_race##same_gender i.id pct_* d_* inc i.cycle if party=="d", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_dem_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_dem_nofe.csv", b se plain wide replace 	

*Republican
eststo clear
eststo: quietly: xi: reg race_gender_total same_race i.id pct_* d_* inc i.cycle if party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_gender i.id pct_* d_* inc i.cycle if party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_race##same_gender i.id pct_* d_* inc i.cycle if party=="r", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_rep_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_rep_nofe.csv", b se plain wide replace 	


*Women only
eststo clear
eststo: quietly: xi: reg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_dem_women_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_dem_women_nofe.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: reg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_rep_women_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_rep_women_nofe.csv", b se plain wide replace 	

*Women of Color ONLY
eststo clear
eststo: quietly: xi: reg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d",robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_dem_woc_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_dem_woc_nofe.csv", b se plain wide replace 	

eststo clear
eststo: quietly: xi: reg race_gender_total same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_total same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_total_rep_woc_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_total_rep_woc_nofe.csv", b se plain wide replace


** GENERAL AND PRIMARY COMBINED **
*Dem
eststo clear
eststo: quietly: xi: areg race_gender_total_all same_race i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_gender i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_race##same_gender i.id pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_all_dem.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_all_dem.csv", b se plain wide replace 	

*Republican
eststo clear
eststo: quietly: xi: areg race_gender_total_all same_race i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_gender i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_race##same_gender i.id pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_all_rep.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_all_rep.csv", b se plain wide replace 	


*Women only
eststo clear
eststo: quietly: xi: areg race_gender_total_all same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_all_dem_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_all_dem_women.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: areg race_gender_total_all same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_all_rep_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_all_rep_women.csv", b se plain wide replace 	



*Women of Color ONLY
eststo clear
eststo: quietly: xi: areg race_gender_total_all same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_all_dem_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_all_dem_woc.csv", b se plain wide replace 	

eststo clear
eststo: quietly: xi: areg race_gender_total_all same_race i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_total_all same_race##same_gender i.id d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_all_rep_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_all_rep_woc.csv", b se plain wide replace 	


* adding controls for competitiveness
global covar_competitiveness cq_forecast Open_Seat
global covar_ideology ps_dw1 ps_dw2

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_competitiveness pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_competitiveness pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_competitiveness pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_dem.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_dem.csv", b se plain wide replace 	

*Republican
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_competitiveness pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_competitiveness pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_competitiveness pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_rep.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_rep.csv", b se plain wide replace 	


*Women only
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_dem_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_dem_women.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_rep_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_rep_women.csv", b se plain wide replace 	

*Women of Color ONLY
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_dem_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_dem_woc.csv", b se plain wide replace 	

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_competitiveness d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_rep_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_comp_rep_woc.csv", b se plain wide replace 	

* adding controls for ideology

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_ideology pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_ideology pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_ideology pct_* d_* inc i.cycle if party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_dem.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_dem.csv", b se plain wide replace 	

*Republican
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_ideology pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_ideology pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_ideology pct_* d_* inc i.cycle if party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_rep.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_rep.csv", b se plain wide replace 	


*Women only
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_dem_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_dem_women.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1"|id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_rep_women.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_rep_women.csv", b se plain wide replace 	

*Women of Color ONLY
eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_dem_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_dem_woc.csv", b se plain wide replace 	

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id $covar_ideology d_* inc i.cycle if (id=="A1"|id=="B1"|id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_rep_woc.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_logtotal_ideo_rep_woc.csv", b se plain wide replace 	



*****************Simple Appendix Regressions by Race-Gender***************

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="A1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="B1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="H1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="W1") & party=="d", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_byrace_dem.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_byrace_dem.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="A1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="B1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="H1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="W1") & party=="r", a(district_final) robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_byrace_rep.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_byrace_rep.csv", b se plain wide replace 	

*no FEs*


eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="A1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="B1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="H1") & party=="d", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="W1") & party=="d", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_byrace_dem_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_byrace_dem_nofe.csv", b se plain wide replace 	


eststo clear
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="A1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="B1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="H1") & party=="r", robust cluster(district_final)
estat ic
eststo: quietly: xi: reg race_gender_logtotal same_race##same_gender pct_A pct_H d_* inc i.cycle if (id=="W1") & party=="r", robust cluster(district_final)
estat ic
esttab using "$dir/Output/ingroup_byrace_rep_nofe.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_byrace_rep_nofe.csv", b se plain wide replace 	


*********Non-Incumbents Only**********

eststo clear
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id i.cycle if inc==0 & party=="d", a(district_final) robust cluster(district_final)
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id pct_* d_* i.cycle if inc==0 & party=="d", a(district_final) robust cluster(district_final)
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id i.cycle if inc==0 & party=="r", a(district_final) robust cluster(district_final)
eststo: quietly: xi: areg race_gender_logtotal same_race##same_gender i.id pct_* d_* i.cycle if inc==0 & party=="r", a(district_final) robust cluster(district_final)

esttab using "$dir/Output/ingroup_gender_race_did_nonincumbents.rtf", se r2 star(+ 0.10 * 0.05 ** 0.01 *** 0.001) replace
esttab using "$dir/Output/ingroup_gender_race_did_nonincumbents.csv", b se plain wide replace 	
